    /**
     * 判断链接
     * author by blue
     * 功能：判断链接使用方式
     */
    fangimjs.define("sdk/judgeSocket", ["swfobject", "event/event", "util/util", "setting/setting"], function (require, exports, module) {
        "use strict";
        module.exports = function () {
            /*flash加载判断操作*/
            var swfobject = require("swfobject"),
                util = require("util/util"),
                event = require("event/event"),
                setting = require("setting/setting").getInstance();
            var socketType = "sdk/flashSocket";
            var vars = fangimjs.data.vars;
            var config = vars.config;
            function loadSwfResultHandle(result) {
                if (result === 1) {
                    socketType = "sdk/flashSocket";
                } else {
                    socketType = "sdk/pollingSocket";
                }
                /*util.setCookie('fang_im_swf_result', result == 1 ? 'ok' : 'no');*/
                util.trace("socket:select", socketType, new Date().getTime());
                event.trigger("socket:select", socketType);
                /*require.async(socketType, function() {

                });*/
            }

            /**
            * 判断浏览器是否支持flash插件
            */
            function flashChecker() {
                var hasFlash = 0;
                var flashVersion = 0;
                var isIE = navigator.userAgent.indexOf('MSIE') > 0;
                var swf, VSwf;
                if (isIE) {
                    swf = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
                    if (swf) {
                        hasFlash = 1;
                        VSwf = swf.GetVariable("$version");
                        flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
                    }
                } else if (navigator.plugins && navigator.plugins.length > 0) {
                    swf = navigator.plugins["Shockwave Flash"];
                    if (swf) {
                        hasFlash = 1;
                        var words = swf.description.split(" ");
                        for (var i = 0; i < words.length; ++i) {
                            if (isNaN(parseInt(words[i]))) {
                                continue;
                            }
                            flashVersion = parseInt(words[i]);
                        }
                    }
                }
                return {f: hasFlash, v: flashVersion};
            }

            function objectVerify(core) {
                var obj = {
                    str: 'false',
                    sub: {
                        arr: [0, 1, 2]
                    }
                };

                try {
                    core.callIM('OBJECT_VERIFY', obj);
                } catch (e) {
                    util.trace('core.callIM OBJECT_VERIFY wrong');
                }
            }


            /**
             * window.FangChat.completed
             * flash打开成功后调用
             *
             */
            var win = window;
            win.FangChat = win.FangChat || {};
            win.FangChat.completed = function () {
                var im_instance = swfobject.getObjectById("fang_im_swf");
                if (im_instance == null) {
                    return;
                }
                swfCompleteListener.remove();
                /*closeDialog();*/
                im_load_status = IM_LOAD_STATUS_LOADED;
                // loadSwfResultHandle(1);
                objectVerify(im_instance);
                //支持flash


                /*for(var a=0;a<im_sendmsg_query.length;a++){
                try{
                im_instance.callIM(CMD_JS_ICON_CLICKED,im_sendmsg_query[a]);
                }catch(c){}
                }
                im_sendmsg_query=[];
                */
            };
            win.FangChat.verifyResult = function(data) {
                data = data[0];
                util.trace('flash call js verifyResult is', data.result);
                if (data.result == 1) {
                    loadSwfResultHandle(1);
                } else {
                    loadSwfResultHandle(0);
                }
            };
            win.FangChat.setMaster = function (data) {
                data = data[0];
                event.trigger("socket:master:set", data);
            };
            win.FangChat.setUserState = function (data) {
                event.trigger('socket:state:set', data[0]);
            };
            win.FangChat.imLog = function (data) {
                if (util.debug) {
                    event.trigger('socket:im:log', data);
                }
            };
            //如果之前判断过不支持flash,则直接打开长轮询，不再判断
            /*if(util.getCookie('fang_im_swf_result') == 'no'){
                loadSwfResultHandle(0);
                return;
            }*/

            var flashPlugin = flashChecker();
            // 如果设置强制使用flash socket 并且浏览器不支持flash插件,则提示用户安装flash 插件.
            if (flashPlugin.f === 0 && config.flash === true) {
                event.trigger('socket:systemInfo:show', {type:'flash_error'});
                return;
            }
            // 如果设置强制使用长轮询或浏览器不支持flash插件,则直接使用长轮询
            if (config.flash === false || flashPlugin.f === 0) {
                loadSwfResultHandle(0);
                return;
            }
            var flashvars = {

            };
            var params = {
                "menu": "false",
                "scale": "noScale",
                "allowFullscreen": "true",
                "allowScriptAccess": "always",
                "bgcolor": "",
                "wmode": "transparent"
            };
            var attributes = {
                id: "fang_im_swf"
            };
            var IM_LOAD_STATUS_UNLOAD = 0,
                IM_LOAD_STATUS_LOADING = 1,
                IM_LOAD_STATUS_LOADED = 2,
                IM_LOAD_STATUS_FAILURE = 3;
            var im_load_status = IM_LOAD_STATUS_UNLOAD;
            var swfCompleteListener = (function () {
                var completeTimer = 0,
                    add = function () {
                        if (completeTimer == 0) {
                            completeTimer = setTimeout(function () {
                                im_load_status = IM_LOAD_STATUS_FAILURE;
                                completeTimer = 0;
                                //不支持flash
                                loadSwfResultHandle(0);
                            }, 3000);
                        }

                    },
                    remove = function () {
                        clearTimeout(completeTimer);
                        completeTimer = 0;
                    };
                return {
                    "add": add,
                    "remove": remove
                }
            })();

            swfobject.embedSWF(
                fangimjs.data.base+setting.SWF_FILE,//+"?_="+Math.random(),
                "swfContainer", "6", "1", "10.0.0",
                "expressInstall.swf",
                flashvars, params, attributes,
                function (e) {
                    if (e.success) {
                        swfCompleteListener.add();
                    } else {
                        loadSwfResultHandle(0);
                    }
                }
            );
        };
    });
